﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBMigrator.Core.DbObjects.Data.Delete;
using DBMigrator.Core.DbObjects.Data.What;
using DBMigrator.Core.DbObjects.Data.Where;
using Rhino.Mocks;
using Xunit;

namespace DBMigrator.Core.Tests.DbObjects.Data
{
    public class DeleteTests
    {
        private readonly IWhat what;
        private readonly IWhere where;

        public DeleteTests()
        {
            what = MockRepository.GenerateMock<IWhat>();
            where = MockRepository.GenerateMock<IWhere>();
        }

        [Fact]
        public void SqlGenerationTypeShouldReturnIDelete()
        {
            Assert.Equal(typeof(IDelete), new Delete(what, where, "TableName").SqlGenerationType);
        }

        [Fact]
        public void ConstructorShouldThrowIfWhatIsNull()
        {
            Assert.Throws<ArgumentNullException>(() => new Delete(null, where, "TableName"));
        }

        [Fact]
        public void ConstructorShouldSetWhat()
        {
            Assert.Equal(what, new Delete(what, where, "TableName").What);
        }

        [Fact]
        public void ConstructorShouldThrowIfWhereIsNull()
        {
            Assert.Throws<ArgumentNullException>(() => new Delete(what, null, "TableName"));
        }

        [Fact]
        public void ConstructorShouldSetWhere()
        {
            Assert.Equal(where, new Delete(what, where, "TableName").Where);
        }

        [Fact]
        public void ConstructorShouldThrowIfTableNameIsNull()
        {
            Assert.Throws<ArgumentNullException>(() => new Delete(what, where, null));
        }

        [Fact]
        public void ConstructorShouldThrowIfTableNameIsEmpty()
        {
            Assert.Throws<ArgumentNullException>(() => new Delete(what, where, string.Empty));
        }

        [Fact]
        public void ConstructorShouldSetTableName()
        {
            var tableName = StringUtil.Random();
            Assert.Equal(tableName, new Delete(what, where, tableName).TableName);
        }
    }
}
